package com.xian.im.modules.command.system.handler;

import com.xian.feign.UserChannelClient;
import com.xian.im.common.constant.CommandCodeConstant;
import com.xian.im.common.constant.CommandConstant;
import com.xian.im.common.proto.MsgRequest;
import com.xian.im.common.proto.MsgResponse;
import com.xian.im.common.utils.sys.SpringContextHolder;
import com.xian.im.modules.command.system.SystemCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

/**
 * @program: xian-im-server
 * @description:
 * @author: liru.xian
 * @create: 2021-02-01 09:06
 */
@Slf4j
public class SystemUserHandler implements SystemCommand {
  /**
   *
   *
   * @param request
   */
  @Override
  public void exec(MsgRequest request) {
    String toAccount = request.getToAccount();
    MsgResponse response = MsgResponse.buildSuccess();
    BeanUtils.copyProperties(request, response);
    response.setCmd(CommandConstant.SYSTEM_CMD);
    response.setCmdCode(CommandCodeConstant.SYSTEM_USER);
    response.setBody(request.getBody());
    UserChannelClient client = SpringContextHolder.getBean(UserChannelClient.class);
    client.pushPlatformMessage(toAccount,response);
  }

  /**
   * code
   *
   * @return
   */
  @Override
  public String cmdCode() {
    return CommandCodeConstant.SYSTEM_USER;
  }
}
